package com.res.share.controller;

import com.res.share.common.WebResponse;
import com.res.share.service.IResArtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

@Controller
@RequestMapping("/nologin")
public class CleanResArticleController {

    @Autowired
    private IResArtService resArtService;

    @GetMapping("/updateLeanResource")
    @ResponseBody
    public String updateLeanResource() {
        Executors.newFixedThreadPool(1).execute(new Runnable() {
            @Override
            public void run() {
                resArtService.updateLeanResource();
            }
        });
        return "1";
    }


    /**
     * 原创
     *
     * @param title
     * @param content
     * @param type
     * @return
     */
    @RequestMapping("/findArticelAI")
    @ResponseBody
    public WebResponse<Map<String, String>> findArticelAI(@RequestParam("title") String title,
                                                          @RequestParam("content") String content,
                                                          @RequestParam("type") Integer type) {
        Map<String, String> articelAI = new HashMap<>();
        if (type == 0) {
            articelAI = resArtService.findArticelAI(title, content);
        } else {
            articelAI = resArtService.findArticelAIOne(title, content);
        }
        return WebResponse.ok(articelAI);

    }

}
